package org.djw.org.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.djw.basic.util.AjaxResult;
import org.djw.basic.util.PageList;
import org.djw.org.domain.Shop;
import org.djw.org.query.ShopQuery;
import org.djw.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店铺管理接口
 */
@RestController
@RequestMapping("/shop")
@Api(tags = "店铺接口",description = "店铺接口详细描述")
public class ShopController {
    @Autowired
    private IShopService shopService;

    /*
    查询一条,全部
    分页加高级查询
    新增或者修改
    删除
     */

    /**
     * 查询一条数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Shop queryById(@PathVariable("id") Long id){
        return shopService.queryById(id);
    }

    /**
     * 查询所有数据
     * @return
     */
    @GetMapping("/list")
    public List<Shop> queryAll(){
        return shopService.queryAll();
    }

    /**
     * 分页高级查询
     * @param query
     * @return
     */
    @PostMapping("/page")
    public PageList<Shop> queryPage(@RequestBody ShopQuery query){
        return shopService.queryPage(query);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            shopService.remove(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后再试");
        }
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    /*@PostMapping("/batch")
    public AjaxResult batch(@RequestBody List<Long> ids){
        try {
            shopService.batch(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后再试");
        }
    }*/

    /**
     * 修改
     * @param shop
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "店铺修改",notes = "如果有id就是修改")
    public AjaxResult update(@RequestBody Shop shop){
        try {
                shopService.update(shop);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后再试");
        }
    }
    /**
     * 新增店铺
     * @param shop
     * @return
     */
    @PostMapping("/settlement")
    @ApiOperation(value = "店铺添加",notes = "添加")
    public AjaxResult settlement(@RequestBody Shop shop){
        try {
                shopService.add(shop);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙,请稍后再试");
        }
    }
}
